package com.me.mygdxgame;

import handlers.BoundedCamera;
import handlers.Content;
import handlers.GameStateManager;
import handlers.MyInput;
import handlers.MyInputProcessor;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Game implements ApplicationListener {
	public static final int V_WIDTH = 400;
	public static final int V_HEIGHT = 240;
	public static final int SCALE = 2;

	private SpriteBatch spriteBacth;
	private BoundedCamera camera;
	private OrthographicCamera HudCamera;

	public static final float STEP = 1 / 60f;
	private GameStateManager gsm;

	public static Content res;

	@Override
	public void create() {
		Texture.setEnforcePotImages(false);
		Gdx.input.setInputProcessor(new MyInputProcessor());

		res = new Content();
		res.loadTexture("images/bunny.png", "bunny");
		res.loadTexture("images/crystal.png", "crystal");
		res.loadTexture("images/hud.png", "hud");
		res.loadTexture("images/bgs.png", "bg");
		res.loadTexture("images/menu.png", "menu");
		res.loadTexture("images/CLOUD.png", "cloud");

		res.loadSound("sfx/jump.wav");
		res.loadSound("sfx/crystal.wav");
		res.loadSound("sfx/levelselect.wav");
		res.loadSound("sfx/hit.wav");
		res.loadSound("sfx/changeblock.wav");

		res.loadMusic("music/bbsong.ogg");
		res.getMusic("bbsong").setLooping(true);
		res.getMusic("bbsong").setVolume(0.5f);
		res.getMusic("bbsong").play();

		spriteBacth = new SpriteBatch();
		camera = new BoundedCamera();
		camera.setToOrtho(false, V_WIDTH, V_HEIGHT);
		HudCamera = new OrthographicCamera();
		HudCamera.setToOrtho(false, V_WIDTH, V_HEIGHT);

		gsm = new GameStateManager(this);
	}

	@Override
	public void dispose() {
		res.DisposeAll();
	}

	@Override
	public void render() {

//		Gdx.gl.glClearColor(51, 102, 255, 1);
		Gdx.gl.glClearColor(0.2f, 0.5f, 1, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		Gdx.graphics.setTitle("Collect Diamond " + " --  FPS : "
				+ Gdx.graphics.getFramesPerSecond());

		gsm.Update(STEP);
		gsm.render();
		MyInput.update();

	}

	@Override
	public void resize(int width, int height) {
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	public SpriteBatch getSpriteBacth() {
		return spriteBacth;
	}

	public void setSpriteBacth(SpriteBatch spriteBacth) {
		this.spriteBacth = spriteBacth;
	}

	public BoundedCamera getCamera() {
		return camera;
	}

	public void setCamera(BoundedCamera camera) {
		this.camera = camera;
	}

	public OrthographicCamera getHudCamera() {
		return HudCamera;
	}

	public void setHudCamera(OrthographicCamera hudCamera) {
		HudCamera = hudCamera;
	}
}
